<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>let命令</title>
  </head>
  <body>
    <div></div>
    <script>
      // 1、声明方式类似于var
      let a1 = 1
      var b1 = 2
      //2、块级作用域  if else while for
      // if(true){
      //     var a2 = 10;
      //     let b2 = 20;
      //     console.log(b2)// 20
      // }
      // console.log(a2)// 10
      // console.log(b2)// b2 is not defined

      //3、不能重复生成变量
      let b3 = 30
      //let b3 = 40;
      //b3 = 40
      console.log(b3)
      //Uncaught SyntaxError: Identifier 'b3' has already been declared语法错误

      // 4、不存在变量提升，不能在变量声明之前提前使用变量
      //var a4;
      // console.log(a4);//undefined
      // var a4 = '测试'

      // console.log(b4);// Uncaught ReferenceError: Cannot access 'b5' before initialization
      // let b4 = "测试"

      //5、不影响作用域链
      //   {
      //     let b5 = "商信"
      //     function fn() {
      //       console.log(b5) //函数作用域下面没有变量，会向上一级作用域里面进行寻找
      //     }
      //     fn()
      //   }
    </script>
  </body>
</html>
